//
// Created by Wei on 2022/5/22.
//


#include <cstring>
#include <iostream>
#include "../src/innodb/page.h"
#include "../src/buffer/buffer_pool.h"
#include "../src/enum/page_type.h"

using namespace std;

int main() {
    cout << sizeof (COMPACT_DATA) << endl;
    auto instance = BufferPool::getInstance();
    for (int i = 0; i < 50; i++) {
        COMPACT_DATA data = COMPACT_DATA{};
        data.id = i + 1;
        char temp[20];
        sprintf(temp, "%c", (i + 1) % 256);
        memcpy(data.c1, temp, 20);
        memcpy(data.c2, temp, 20);
        memcpy(data.c3, temp, 20);
        memcpy(data.c4, temp, 20);
        int res = instance->get_root()->insert(&data);
        cout << "id:" << i + 1 << " insert result:" << res << endl;
    }
    for (int i = 149; i >= 50; i--) {
        COMPACT_DATA data = COMPACT_DATA{};
        data.id = i + 1;
        char temp[20];
        sprintf(temp, "%c", (i + 1) % 256);
        memcpy(data.c1, temp, 20);
        memcpy(data.c2, temp, 20);
        memcpy(data.c3, temp, 20);
        memcpy(data.c4, temp, 20);
        int res = instance->get_root()->insert(&data);
        cout << "id:" << i + 1 << " insert result:" << res << endl;
    }
    for (int i = 150; i <= 200; i++) {
        COMPACT_DATA data = COMPACT_DATA{};
        data.id = i + 1;
        char temp[20];
        sprintf(temp, "%c", (i + 1) % 256);
        memcpy(data.c1, temp, 20);
        memcpy(data.c2, temp, 20);
        memcpy(data.c3, temp, 20);
        memcpy(data.c4, temp, 20);
        int res = instance->get_root()->insert(&data);
        cout << "id:" << i + 1 << " insert result:" << res << endl;
    }
    cout << "insert done" << endl;


    COMPACT_DATA *check = instance->get_root()->search(100);
    if (check)
        check->check();
    cout << "single search end" << endl;

    COMPACT_DATA *tests[300];
    int nums = instance->get_root()->search(1, 200, tests);
    for (int i = 0; i < nums; i++) {
        tests[i]->check();
        delete tests[i];
    }
    cout << "range search end" << endl;

    instance->destroy();

    return 0;
}